package org.objective.ddl.commands;

import org.common.service.ServiceRegister;
import org.objective.command.AuthToken;
import org.objective.command.Command;
import org.objective.command.CommandResult;
import org.objective.command.VoidCommandResult;
import org.objective.ddl.type.DDLFieldInfo;

import org.objective.service.DDLService;
import static org.utils.fp.collection.CollectionFactory.*;

/**
 *
 * @author gus
 */
public class CreateUserTableCommand implements Command
{
    private static final long serialVersionUID = -3299476474653776866L;
    private String tableName;
    private DDLFieldInfo[] fields;

    public CreateUserTableCommand(String tableName, DDLFieldInfo[] fields)
    {
        this.tableName = tableName;
        this.fields = fields;
    }

    @Override
    public Object[] getParameters()
    {
        return array(tableName, fields);
    }

    @Override
    public CommandResult execute(ServiceRegister provider, AuthToken token) throws Exception
    {
        DDLService service = provider.getService(DDLService.class);
        service.createUserTable(tableName, fields);
        return new VoidCommandResult();
    }
}
